let vm = new Vue({
    el: '#app',  //选中整个main
    data() {
        return {
            title:'',
            page:{},
        }
    },
    methods: {
        selectPage: function (start=1,pageSize=3) {
            axios({
                url: `article/selectPage/${start}/${pageSize}`,
                params: {
                    title:this.title
                }
            }).then(response => {
                //不成功提示
                if (response.data.success) {
                    this.page=response.data.obj;
                } else {
                    //登陆失败
                    layer.msg(response.data.msg);
                }
            }).catch(error => {
                layer.msg(error.message);
            })
        },
        todetil:function (art) {
            layer.obj = art;
            layer.open({
                type: 2,
                title: '详情',
                maxmin: true,
                shadeClose: true, //点击遮罩关闭层
                area : ['1000px' , '80%'],
                content: 'html/article_detail.html',
            });
        },
        getFocus:function(){
            let parse = JSON.parse(sessionStorage.getItem("user"));
            this.focus.userId=parse.id;
            axios({
                url: `user/getFocus/${parse.id}`,
            }).then(result=>{
                this.focusIds=result.data.obj;
                for (let i = 0; i <this.focusIds.length ; i++) {
                    for (let j = 0; j <this.page.list.length ; j++) {
                        // console.log(this.focusIds[i].userFocusId+':'+this.page.list[j].id)
                        if (this.focusIds[i].userFocusId==this.page.list[j].id){
                            this.page.list[j].flag=true;
                            // console.log(this.page.list[j].flag)
                        }
                    }
                }
            }).catch(error=>{

            })
        },
        setFocus:function (focusId,event) {
            this.focus.userFocusId=focusId;
            console.log(event)
            if (event.target.checked){
                //关注
                axios.post("user/focus",this.focus).then(result=>{
                    layer.msg(result.data.msg)
                }).catch(error=>{
                    layer.msg(error.message);
                })
                // console.log("选中了")
            }else {
                //取消关注
                axios.put("user/cancekFocus",this.focus).then(result=>{
                    layer.msg(result.data.msg)
                }).catch(error=>{
                    layer.msg(error.message)
                })
                // console.log("取消选中")
            }
        }
    },
    created:function () {
        this.selectPage();
        console.log(this.page)
    }
});